package cn.jwm.permission.controller;


import cn.jwm.annotation.JwmPermission;
import cn.jwm.permission.domain.Permission;
import cn.jwm.permission.query.PermissionQuery;
import cn.jwm.permission.service.IPermissionService;
import cn.jwm.utils.AjaxResult;
import cn.jwm.utils.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@JwmPermission(name = "权限管理")
@RestController
@RequestMapping("/permission")
public class PermissionController {

    @Autowired
    private IPermissionService permissionService;

    @JwmPermission(name = "分页查询")
    @PostMapping
    public AjaxResult listPage(@RequestBody PermissionQuery query){
        try {
            // 调用Service做分页查询
            PageList<Permission> pageList = permissionService.page(query);
            return AjaxResult.me().setDataObj(pageList);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("分页查询失败!"+e.getMessage());
        }
    }

}
